package com.anysoft.base;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.anysoft.utils.AnalyticsUtils;
import com.anysoft.view.dialog.LoadingDialog;

public class BaseFragment extends Fragment {
    private LoadingDialog loadingDialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onResume() {
        super.onResume();
        AnalyticsUtils.onResumeToFragment(getActivity());
    }

    @Override
    public void onPause() {
        super.onPause();
        AnalyticsUtils.onPauseToFragment(getActivity());
    }

    public void showLoading(Context context) {
        if (loadingDialog == null && !((BaseActivity) context).isFinishing()) {
            loadingDialog = new LoadingDialog(context);
            loadingDialog.setCancelable(false);
            loadingDialog.setAnimationEnable(true);
            loadingDialog.show();
        }
    }

    public void hideLoading() {
        if (loadingDialog != null) {
            loadingDialog.dismiss();
            loadingDialog = null;
        }
    }
}
